def max_m(arr):
    total = sum(arr)
    n = len(arr)
    if total == 0:
        return n  # 所有元素都是0，可以分成n份
    max_num = max(arr)
    max_possible = total // max_num
    max_possible = min(max_possible, n)  # 不能超过数组长度
    
    for m in range(max_possible, 0, -1):
        if total % m != 0:
            continue
        target = total // m
        left = 0
        right = n - 1
        count = 0
        valid = True
        while left <= right:
            if arr[left] == target:
                count += 1
                left += 1
            elif arr[left] + arr[right] == target:
                count += 1
                left += 1
                right -= 1
            else:
                # 需要累加多个元素
                current_sum = arr[left]
                left += 1
                while left <= right and current_sum < target:
                    current_sum += arr[left]
                    left += 1
                if current_sum == target:
                    count += 1
                else:
                    valid = False
                    break
        if valid and count == m and left > right:
            return m
    return 1  # 至少可以分成1份

# 示例测试
# 测试用例
if __name__ == "__main__":    
    # 测试用例
    test_cases = [
        [6, 4, 3, 3, 2],
        [10, 8, 6, 4, 2],
        [7, 7, 7],
        [5, 4, 3, 2, 1],
        [5, 4, 3, 2],
    ]
    
    for i, test in enumerate(test_cases):
        print(f"测试用例 {i+1} {test}: 最大的m值为 {max_m(test)}")